package org.spring.demo.service;

import org.apache.activemq.Message;
import org.apache.activemq.command.ActiveMQTextMessage;
import org.spring.autoType.utils.TypeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.jms.JMSException;

/**
 * @author LHB
 * @date 2019/12/19 13:00
 */
@Service
@EnableScheduling
public class MqService {


    @Resource(name = "activeTest1")
    private JmsTemplate jmsTemplate;

    @Resource(name = "activeTest2")
    private JmsTemplate jmsTemplate2;

    @JmsListener(destination = "test1", containerFactory = "listenerFactory")
    public void mes(Message message) throws JMSException {
        ActiveMQTextMessage activeMQTextMessage = (ActiveMQTextMessage) message;
        System.out.println(activeMQTextMessage.getText());

    }

    @Async
    @JmsListener(destination = "test2", containerFactory = "listenerFactory2")
    public void mes2(Message message) throws JMSException, InterruptedException {
        ActiveMQTextMessage activeMQTextMessage = (ActiveMQTextMessage) message;
        System.out.println(activeMQTextMessage.getText());
        Thread.sleep(10000);
    }

}
